//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.come.until;

import java.math.BigInteger;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

public class AESUtil {
	public AESUtil() {
	}

	public static byte[] AESJDKEncode(String message, String password) {
		try {
			KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
			keyGenerator.init(128, new SecureRandom(password.getBytes()));
			SecretKey secretKey = keyGenerator.generateKey();
			byte[] enCodeFormat = secretKey.getEncoded();
			SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
			Cipher cipher = Cipher.getInstance("AES");
			cipher.init(1, key);
			byte[] result = cipher.doFinal(message.getBytes("utf-8"));
			return result;
		} catch (Exception var8) {
			return null;
		}
	}

	public static String AESJDKDncode(byte[] msg, String password) {
		try {
			if (msg == null) {
				return "";
			} else {
				KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
				SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
				secureRandom.setSeed(password.getBytes());
				keyGenerator.init(128, secureRandom);
				SecretKey secretKey = keyGenerator.generateKey();
				byte[] enCodeFormat = secretKey.getEncoded();
				SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
				Cipher cipher = Cipher.getInstance("AES");
				cipher.init(2, key);
				byte[] result = cipher.doFinal(msg);
				String info = new String(result, "utf-8");
				return info;
			}
		} catch (Exception var11) {
			var11.printStackTrace();
			return null;
		}
	}

	public static final byte[] hex2byte(String hex) throws IllegalArgumentException {
		if (hex.length() % 2 != 0) {
			throw new IllegalArgumentException();
		} else {
			char[] arr = hex.toCharArray();
			byte[] b = new byte[hex.length() / 2];
			int i = 0;
			int j = 0;

			for(int l = hex.length(); i < l; ++j) {
				String swap = "" + arr[i++] + arr[i];
				int byteint = Integer.parseInt(swap, 16) & 255;
				b[j] = (new Integer(byteint)).byteValue();
				++i;
			}

			return b;
		}
	}

	public static String binary(byte[] bytes, int radix) {
		return (new BigInteger(1, bytes)).toString(radix);
	}
}
